package com.hualude.roadsign.repository;

import com.hualude.roadsign.dto.DTRequestDto;
import com.hualude.roadsign.dto.FaultCountDto;
import com.hualude.roadsign.dto.SignalMachineDto;
import com.hualude.roadsign.dto.SignalMachineFaultDto;
import com.hualude.roadsign.model.SignalMachineEntity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.math.BigInteger;
import java.util.List;

/**
 * Created by ding on 2017/9/21.
 */
public interface SignalMachineFaultCountRepository extends CrudRepository<SignalMachineEntity, Long> {

    /**
     * @Description: 得到该维护公司在该年的处理数量
     * @Author: jiang-weirong
     * @Date: 2017/9/20 13:44
     */
    public List<String> getDealCounts(Integer year, String orgIds) throws Exception;

    /**
     * @Description: 得到该维护公司在该年的上报数量
     * @Author: jiang-weirong
     * @Date: 2017/9/20 13:48
     */
    public List<String> getReportCounts(Integer year, String orgIds) throws Exception;

    /**
     * @Description: 按年月统计报修金额
     * @Author: jiang-weirong
     * @Date: 2017/9/20 14:00
     */
    public List<FaultCountDto> getExpenseCounts(Integer year, String orgIds) throws Exception;

    public Integer getFaultCount4DT(DTRequestDto dtRequestDto, Integer actor, String orgIds) throws Exception;

    /**
     * @Description: 故障上报处理DT
     * @Author: jiang-weirong
     * @Date: 2017/9/20 14:40
     */
    public List<SignalMachineFaultDto> getFault4DT(DTRequestDto dtRequestDto, Integer actor, String orgIds) throws Exception;

    public Integer getDeviceCount4DT(DTRequestDto dtRequestDto, Integer actor, String orgIds, Integer userId) throws Exception;

    /**
     * @Description: 设备的故障处理DT
     * @Author: jiang-weirong
     * @Date: 2017/9/20 15:00
     */
    public List<SignalMachineFaultDto> getDevice4DT(DTRequestDto dtRequestDto, Integer actor, String orgIds, Integer userId) throws Exception;


    /**
     * @Description: 位置统计datatables4DT count
     * @Author: pan-jianan
     * @Date: 2017/9/20 14:00
     */
    public Integer getMachineCount4DT(DTRequestDto dtRequestDto, Integer actor, String orgIds) throws Exception;

    /**
     * @Description: 位置统计datatables4DT
     * @Author: pan-jianan
     * @Date: 2017/9/20 14:00
     */
    public List<SignalMachineDto> getMachine4DT(DTRequestDto dtRequestDto, Integer actor, String orgIds) throws Exception;


    /**
     * @Description: 得到表中的全部省份
     * @Author: pan-jianan
     * @Date: 2017/9/20 14:00
     */
    public List<String> getProvinceName(String orgIds) throws Exception;

    /**
     * @Description: 按照省份得到城市
     * @Author: pan-jianan
     * @Date: 2017/9/20 14:00
     */
    public List<String> getCityName(String orgIds, String provinceName) throws Exception;

    /**
     * @Description: 获取表中的所有相关的区域名
     * @Author: pan-jianan
     * @Date: 2017/9/20 14:00
     */
    public List<String> getAllAreaName(String orgIds, String provinceName, String cityName) throws Exception;

    /**
     * @Description: 获取起始路段
     * @Author: pan-jianan
     * @Date: 2017/9/20 14:00
     */
    public List<String> getStartRoadName(String orgIds, String provinceName, String cityName, String areaName,
                                         String endRoadName) throws Exception;

    /**
     * @Description: 根据起始路段获取终止路段
     * @Author: pan-jianan
     * @Date: 2017/9/20 14:00
     */
    public List<String> getEndRoadName(String orgIds, String startRoad, String provinceName, String cityName, String areaName) throws Exception;

    /**
     * @Description: 得到某年按标志分类各个标志的数量
     * @Author: pan-jianan
     * @Date: 2017/9/20 14:00
     */
    public List<Integer> getSignalMachineTypeCounts(String orgIds, String time, String province, String city, String area) throws Exception;


    /**
     * @Description: DTO4
     * @Author: lin-anqian
     * @Date: 2017/5/4 23:36
     */
    public List<SignalMachineDto> getMachineDtos4DT(DTRequestDto dtRequestDto, Integer actor, String orgIds, Integer userId) throws Exception;


    /**
     * @Description: count(*) 无法map
     * @Author: lin-anqian
     * @Date: 2017/5/5 2:16
     */
    public List<BigInteger> getMachineCounts(DTRequestDto dtRequestDto, Integer actor, String orgIds, Integer userId) throws Exception;

    /**
     * @Description:
     * @Author: lin-anqian
     * @Date: 2017/5/18 21:04
     */
    @Query(value = "SELECT sm.signalMachineType FROM SignalMachineEntity sm, OrgEntity e WHERE \n" +
            "sm.signalMachineOrgId=e.orgId and sm.signalMachineProvince = ?1 AND sm.signalMachineCity = ?2 AND sm.signalMachineArea = ?3  AND e.orgName = ?4" +
            " ORDER BY sm.signalMachineType")
    public List<Integer> getPerMachineCountsByRoad(String province, String city, String area, String orgName) throws Exception;

}
